package com.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Test20 {
    public static void main(String[] args) {

        ArrayList<NewsTitle> list = new ArrayList<>();
        list.add(new NewsTitle(1, "demo", "author"));
        list.add(new NewsTitle(2, "test", "author"));
        list.add(new NewsTitle(3, "day", "author"));
        list.add(new NewsTitle(4, "sun", "author"));
        list.add(new NewsTitle(5, "win", "author"));
        list.add(new NewsTitle(6, "win", "author"));

        String test = "";

        Map<String, List<NewsTitle>> collect = list.stream().collect(Collectors.groupingBy(item -> item.getTitle()));
        for (Map.Entry<String, List<NewsTitle>> listEntry : collect.entrySet()) {
            String key = listEntry.getKey();
            List<NewsTitle> value = listEntry.getValue();
            if (value.size() > 1) {
                test = test + "元素" + key + "存在" + value.size() + "个,";
            }
        }

        System.out.println(test);

    }
}
